﻿using System;
using System.Xml.Serialization;
using System.Web.Script.Serialization;

using Fuse8.DomainFramework.CacheService;
using Fuse8.DomainFramework.BusinessService;

namespace Fuse8.ContentManagementFramework.Domain
{
    [Serializable]
    public partial class CmsMediaContent: CmsSiteEntityObject
    {
        #region Linked field

        private CmsMedia _media;

        #endregion

        #region Properties

        public virtual int MediaId { get; set; }

        public virtual string MediaContentName { get; set; }

        public virtual string MetaCode { get; set; }

        public virtual string Description { get; set; }

        public virtual bool BlockFromSearchEngines { get; set; }

        #endregion

        #region Linked property

        [XmlIgnore]
        [ScriptIgnore]
        public CmsMedia Media
        {
            get
            {
                if (_media == null)
                {
                    var businessFacade = new BusinessServiceFacade<CmsMedia, int>();
                    if (businessFacade != null)
                    {
                        _media = businessFacade.FindOne(MediaId);
                    }
                }

                return _media;
            }
            set
            {
                MediaId = value != null ? value.Id : 0;

                if (_media != null)
                {
                    _media = _media.Id == MediaId ? value : null;
                }
                else
                {
                    _media = value;
                }
            }
        }

        #endregion

        #region Constructor

        public CmsMediaContent()
        { }

        #endregion

        #region EntityObject override

        public override string TypeParameter
        {
            get
            {
                return "MediaContent";
            }
        }

        #endregion
    }
}
